package xyf.p10.dp;

/**
 * ClassName: P0198_Rob
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:27 AM
 * Version: 1.0
 **/
public class P0198_Rob
{
    public int rob(int[] nums)
    {
        int[][] dp = new int[nums.length][2];
        dp[0][0] = 0;
        dp[0][1] = nums[0];

        int max = Math.max(dp[0][0], dp[0][1]);
        for (int i = 1; i < nums.length; i++)
        {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][1] = dp[i - 1][0] + nums[i];

            max = Math.max(dp[i][0], max);
            max = Math.max(dp[i][1], max);
        }
        return max;
    }
}